import request from '../../utils/request'
import type { LoginRequest, RegisterRequest, LoginResponse, ApiResponse } from '../../types/auth'

/**
 * 认证相关API
 */
export const authApi = {
  /**
   * 用户登录
   * @param data 登录信息
   */
  login(data: LoginRequest) {
    return request.post('/auth/login', data) as Promise<ApiResponse<LoginResponse>>
  },

  /**
   * 用户注册
   * @param data 注册信息
   */
  register(data: RegisterRequest) {
    return request.post('/auth/register', data) as Promise<ApiResponse<any>>
  },

  /**
   * 刷新令牌
   * @param refreshToken 刷新令牌
   */
  refreshToken(refreshToken: string) {
    return request.post('/auth/refresh', { refreshToken }) as Promise<ApiResponse<LoginResponse>>
  },

  /**
   * 用户登出
   */
  logout() {
    return request.post('/auth/logout') as Promise<ApiResponse<any>>
  }
}